import os

from moviepy import editor

'''
视频播放速度调整
'''

def resize_video(path, newPath, prefix, speed):
    if not os.path.exists(newPath):
        os.makedirs(newPath)
    for dirpath, dirnames, filenames in os.walk(path):
        count = 1
        for filename in filenames:
            namecount = len(filenames)
            try:
                sc=editor.VideoFileClip(os.path.join(path, filename))
                sc1=sc.fx(editor.vfx.speedx,speed)
                sc1.write_videofile(os.path.join(newPath, prefix+filename), bitrate='100000k',threads=2)
                print("文件总数{}，当前完成视频 {} 为第{}个".format(namecount, filename, count))
            except Exception as e:
                print(e)
                continue
            count += 1

if __name__ == '__main__':
    # path = r'D:\beautyleg-1'  # 原文件文件夹路径
    path = r'D:\HYLiteResources\video-1'  # 原文件文件夹路径
    # newPath = r'D:\beautyleg-resize'  # 压缩好的文件文件夹路径
    newPath = r'D:\HYLiteResources\video-1-resize'  # 压缩好的文件文件夹路径
    prefix = ''  # 压缩好后的文件前缀
    speed = 1
    resize_video(path, newPath, prefix,speed)
